package com.ruoyi.fpa.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fpa.domain.GenReferenceColumn;
import com.ruoyi.fpa.service.IGenReferenceColumnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外键关联Controller
 * 
 * @author koradji@116.com
 * @date 2023-09-17
 */
@RestController
@RequestMapping("/fpa/referenceColumn")
public class GenReferenceColumnController extends BaseController
{
    @Autowired
    private IGenReferenceColumnService genReferenceColumnService;

    /**
     * 查询外键关联列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:list')")
    @GetMapping("/list")
    public TableDataInfo list(GenReferenceColumn genReferenceColumn)
    {
        startPage();
        List<GenReferenceColumn> list = genReferenceColumnService.selectGenReferenceColumnList(genReferenceColumn);
        return getDataTable(list);
    }

    /**
     * 导出外键关联列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:export')")
    @Log(title = "外键关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GenReferenceColumn genReferenceColumn)
    {
        List<GenReferenceColumn> list = genReferenceColumnService.selectGenReferenceColumnList(genReferenceColumn);
        ExcelUtil<GenReferenceColumn> util = new ExcelUtil<GenReferenceColumn>(GenReferenceColumn.class);
        util.exportExcel(response, list, "外键关联数据");
    }

    /**
     * 获取外键关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:query')")
    @GetMapping(value = "/{referenceColumnId}")
    public AjaxResult getInfo(@PathVariable("referenceColumnId") Long referenceColumnId)
    {
        return success(genReferenceColumnService.selectGenReferenceColumnByReferenceColumnId(referenceColumnId));
    }

    /**
     * 新增外键关联
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:add')")
    @Log(title = "外键关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GenReferenceColumn genReferenceColumn)
    {
        return toAjax(genReferenceColumnService.insertGenReferenceColumn(genReferenceColumn));
    }

    /**
     * 修改外键关联
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:edit')")
    @Log(title = "外键关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GenReferenceColumn genReferenceColumn)
    {
        return toAjax(genReferenceColumnService.updateGenReferenceColumn(genReferenceColumn));
    }

    /**
     * 删除外键关联
     */
    @PreAuthorize("@ss.hasPermi('fpa:referenceColumn:remove')")
    @Log(title = "外键关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{referenceColumnIds}")
    public AjaxResult remove(@PathVariable Long[] referenceColumnIds)
    {
        return toAjax(genReferenceColumnService.deleteGenReferenceColumnByReferenceColumnIds(referenceColumnIds));
    }
}
